#include <PopupDefaultLogger.hpp>
#include <PopupSqlite3Database.hpp>
#include <string>

using namespace Popup;
using namespace std;

static PopupDefaultLogger logger;

static void dump(const PopupDatabaseUser * user)
{
  logger.appendLog(POPUP_LOG_INFO,
		   "id=%u name=%s nickname=%s avatar=%s",
		   user->getID(), user->getLogin().c_str(),
		   user->getNickname().c_str(), user->getAvatarPath().c_str());
}

int main(int argc, char *argv[])
{
  if (argc <= 1) 
  {
    logger.appendLog(POPUP_LOG_ERROR, "Usage: %s <file.db>\n", argv[0]);
  } 
  else 
  {
    PopupSqlite3Database database(string(argv[1]), &logger);
    string message;

    PopupDatabaseUser *user = database.connect("guigui", "bonjour", message);
    
    user = database.newUser("guigui", "bonjour", "Maqui de Daube", "./path.png", message);

    if (user != 0) {
      dump(user);
    }

    PopupDatabaseUser *user2 = database.newUser("guigui", "bonjourno", 
						"Maqui de Daube2", "./path.png", message);
    
    user2 = database.newUser("guigui2", "bonjourno", 
			     "Maqui de Daube2", "./path.png", message);
    delete user2;
    
    user2 = database.connect("guigui2", "bonjourno", message);
    
    if (user2 != 0) {
      dump(user2);
    }

    database.updateNickname(user2, "COnnardo", message);
    dump(user2);

    database.updateNickname(user2, "Maqui de Daube", message);

    PopupDatabaseUser *user3 = database.connect("guigui2", "bonjour", message);
  }
  return 0;
}
